<?php
/**
 * Unity PC 端素材制作软件 查询预设素材（画法名称）
 *
 * Author: Zeon
 * Date: 2018/4/2
 * Created by Panxsoft.
 */
namespace App\Http\Controllers\PC;

use App\Http\Controllers\ApiController;
use App\Http\Requests\PC\PanxAssetIndexRequest;
use App\Models\Panx\PanxAsset;
use Illuminate\Database\Eloquent\Builder;

class PanxAssetController extends ApiController
{
    const ROUTE_INDEX = 'pc.panx-asset.index';

    /**
     * 显示/查询所有panx素材
     *
     * @param PanxAssetIndexRequest $request
     *
     * @return \Illuminate\Http\Response
     */
    public function index(PanxAssetIndexRequest $request)
    {
        $type = $request->type;

        $assets = (new PanxAsset)
            ->filterOnShelf()
            ->orderByDefaultLatest($request->order_by, $request->sort)
            ->when($type, function (Builder $builder, $type) {
                $builder->where('type', $type);
            })
            ->paginate($request->per_page ?? 15);

        return $this->response(compact('assets'));
    }

}
